package lvbu.wang.lvbuoperator.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import lvbu.wang.lvbuoperator.R;
import lvbu.wang.lvbuoperator.bean.FileBean;

/**
 * Created by DaiQing.Zha on 2018/10/21 0021.
 */
public class LocalFileAdapter extends BaseAdapter{

    private Context context;
    private List<FileBean> fileBeanList;

    public LocalFileAdapter(Context context, List<FileBean> fileBeanList) {
        this.context = context;
        this.fileBeanList = fileBeanList;
    }

    @Override
    public int getCount() {
        return fileBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return fileBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if(convertView==null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_local_file, null);
            holder.tv_filename = (TextView)convertView.findViewById(R.id.tv_fileName);
            holder.tv_filePath = (TextView) convertView.findViewById(R.id.tv_filePath);
            holder.tv_fileSize = (TextView) convertView.findViewById(R.id.tv_fileSize);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder)convertView.getTag();
        }
        FileBean fileBean = fileBeanList.get(position);
        holder.tv_filename.setText(fileBean.getName());
        holder.tv_filePath.setText(fileBean.getPath());
        holder.tv_fileSize.setText(fileBean.getSize());
        return convertView;
    }

    class ViewHolder{

        private TextView tv_filename;
        private TextView tv_filePath;
        private TextView tv_fileSize;
    }
}
